package com.mjw.zstu.controller;

import com.mjw.zstu.entity.Type;
import com.mjw.zstu.resultDto.JsonResult;
import com.mjw.zstu.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("type")
public class TypeController {
    @Autowired
    TypeService typeService;
    @RequestMapping("list")
    public JsonResult getList(@RequestParam  int pageNum, int pageSize){
        return new JsonResult(200,"获取成功",typeService.getlist(pageNum,pageSize));
    }
    @RequestMapping("delete")
    public JsonResult delete(@RequestParam int id){
        int success=typeService.deleteType(id);
        if(success==1){
            return new JsonResult(200,"删除成功",null);
        }
        return new JsonResult(500,"删除失败",null);
    }
    @RequestMapping("add")
    public JsonResult add(@RequestBody Type type){
        int success=typeService.addType(type);
        if(success==1){
            return new JsonResult(200,"添加成功",type);
        }
        return new JsonResult(500,"添加失败",null);
    }
    @RequestMapping("update")
    public JsonResult update(@RequestBody Type type){
        return typeService.update(type);
//        return new JsonResult(20)
    }
}
